package org.hnxxxy.ebms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.hnxxxy.ebms.common.Result;
import org.hnxxxy.ebms.pojo.Expense;
import org.hnxxxy.ebms.pojo.RecruitStu;
import org.hnxxxy.ebms.service.ExpenseService;
import org.hnxxxy.ebms.service.RecruitStuService;
import org.hnxxxy.ebms.vo.ExpenseVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WANGWEI
 * @since 2021-06-10
 */
@RestController
@RequestMapping("//expense")
public class ExpenseController {
    @Autowired
    public ExpenseService expenseService;

    @PostMapping("/add")
    @ApiOperation(value = "增加报销申请")
    public Result<String> addExpense(@RequestBody Expense expense){
        return expenseService.add(expense);
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除报销申请")
    public Result<String> delExpense(@PathVariable("id") Integer id){
        if (expenseService.removeById(id)){
            return Result.success(200,"删除成功");
        }
        return Result.fail("删除失败");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改报销申请")
    public Result<String> updateExpense(@RequestBody ExpenseVo expense){
        Expense newExpense = new Expense();
        BeanUtils.copyProperties(expense,newExpense);
        if (expenseService.updateById(newExpense)){
            return Result.success(200,"修改成功");
        }
        return Result.fail("删除失败");
    }

    @GetMapping("/get/{page}")
    @ApiOperation(value = "查询报销申请")
    public Result<IPage<ExpenseVo>> getExpense(@PathVariable("page") int page){
        return expenseService.getExpense(page);
    }


}
